-------------------------------
--------CHAIR THROWING---------
-------------GUN---------------
-------------------------------
----------SHARED---------------
-------------------------------

if (SERVER) then


   AddCSLuaFile ("shared.lua");


   SWEP.Weight = 5;
   SWEP.AutoSwitchTo = false;
   SWEP.AutoSwitchFrom = false;

end

if (CLIENT) then


   SWEP.PrintName = "Chair throwing gun";
   SWEP.Slot = 3;
   SWEP.SlotPos = 1;
   SWEP.DrawAmmo = false;
   SWEP.DrawCrosshair = true;

end


SWEP.Author = "Not Taco";
SWEP.Contact = "nottaco@hotmail.com";
SWEP.Purpose = "To throw chairs";
SWEP.Instuctions ="Mouse1: Throw Office chair; Mouse2: Throw Wooden Chair;";
SWEP.category = "Prop Launchers";

SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;

SWEP.ViewModel = "models/weapons/v_pistol.mdl";
SWEP.WorldModel = "models/weapons/w_pistol.mdl";

SWEP.Primary.Recoil		= 1.5 --how much the gun goes up when you shoot it
SWEP.Primary.Damage		= 50 --how much damage it does per shot
SWEP.Primary.NumShots		= 1 --Number of bullets that come out per shot, set to more than 1 if it is a shotgun basically
SWEP.Primary.Cone		= 0 --This is how accurate your gun is, a cone of 0 is completely accurate, a cone of 1 is horribly accurate
SWEP.Primary.ClipSize		= 20 --Explained above
SWEP.Primary.Delay		= 3 --delay in seconds between each shot
SWEP.Primary.DefaultClip		= 360 --explained above
SWEP.Primary.Automatic		= false --explained above
SWEP.Primary.Ammo		= "pistol" --explained above

local ShootSound = Sound ( "Metal.SawbladeStick" );

function SWEP:Reload()
end

function SWEP:Think()
end

function SWEP:Initialize()
	if ( SERVER ) then
	self:SetWeaponHoldType( self.HoldType )
	end
end

function SWEP:throw_attack (model_file)

	local tr = self.Owner:GetEyeTrace();

	self.Weapon:EmitSound (ShootSound);
	self.BaseClass.ShootEffects (self);

	if (!SERVER) then return end;

	local ent = ents.Create ( "prop_physics" );
	ent:SetModel (model_file);

	ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));
	ent:SetAngles (self.Owner:EyeAngles());
	ent:Spawn();

	local phys = ent:GetPhysicsObject();

	local shot_length = tr.HitPos:Length();
	phys.ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));


	cleanup.Add (self.Owner, "props", ent);

	undo.Create ("Thrown chairs");
	undo.AddEntity (ent);
	undo.SetPlayer (self.OWner);
	undo.Finish();
end

function SWEP:PrimaryAttack()

	self:throw_attack ("models/props/cs_office/Chair_office.mdl");
end

function SWEP:SecondaryAttack()

	self:throw_attack ("models/props_c17/FurnitureChair001a.mdl");
end
